package com.zhl.scheduling.service.impl;

import com.zhl.scheduling.mapper.DepartmentMapper;
import com.zhl.scheduling.mapper.WorkpieceCategoryMapper;
import com.zhl.scheduling.model.entity.Department;
import com.zhl.scheduling.model.entity.WorkpieceCategory;
import com.zhl.scheduling.model.vo.ResStatus;
import com.zhl.scheduling.model.vo.ResultVO;
import com.zhl.scheduling.service.InitService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: ZhangLu In DLUT
 * @since: 1.0.0
 * @Description: 初始化接口的实现类
 */
@Service
public class InitServiceImpl implements InitService {

    @Resource
    private WorkpieceCategoryMapper workpieceCategoryMapper;

    @Resource
    private DepartmentMapper departmentMapper;

    /**
     * 获取工件类别信息
     * @return ResultVO用作封装给前端的数据
     */
    @Override
    public ResultVO getCategoryOpt() {
        List<WorkpieceCategory> workpieceCategories = workpieceCategoryMapper.selectAll();
        if (CollectionUtils.isEmpty(workpieceCategories)) {
            return new ResultVO(ResStatus.NO, "获取工件类别失败", null);
        }else {
            return new ResultVO(ResStatus.OK, "获取工件类别成功", workpieceCategories);
        }
    }

    /**
     * 获取部门列表信息
     * @return ResultVO用作封装给前端的数据
     */
    @Override
    public ResultVO getDepartmentOpt() {
        List<Department> departments = departmentMapper.selectAll();
        if (departments.isEmpty()) {
            return new ResultVO(ResStatus.NO, "获取部门类别失败", null);
        } else {
            return new ResultVO(ResStatus.OK, "获取部门类别成功", departments);
        }
    }
}
